package com.hk.asyncprocess.fanoutvswork;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

@Slf4j
@RestController
@RequestMapping("workqueuewrong")
@Configuration
public class WorkQueueWrong {

    private static final String EXCHANGE = "newuserExchange";

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping
    public void sendMessage() {
        rabbitTemplate.convertAndSend(EXCHANGE, "", UUID.randomUUID().toString());
    }

    //使用匿名队列作为消息队列
    @Bean
    public Queue queue() {
        return new AnonymousQueue();
    }

    //声明DirectExchange交换机，绑定队列到交换机
    @Bean
    public Declarables declarable() {
        DirectExchange directExchange = new DirectExchange(EXCHANGE);
        return new Declarables(queue(),
                directExchange,
                BindingBuilder.bind(queue()).to(directExchange).with(""));
    }





}
